<?php
// +----------------------------------------------------------------------
// | sfadmin - Suifeng Administration
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2020 http://suifeng.tech All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: suifeng <1787585212@qq.com>
// +----------------------------------------------------------------------

namespace app\admin\helper;

final class Format
{
    public function date($ts)
    {
        return date(config('SYS_DATE_FORMAT'), $ts);
    }

    public function date_time($ts)
    {
        return date(config('SYS_DATE_FORMAT') . ' ' . config('SYS_TIME_FORMAT'), $ts);
    }

    public function file_size($bytes)
    {
        $rank = 0;
        $size = $bytes;
        $unit = "B";
        while ($size > 1024){
            $size = $size / 1024;
            $rank++;
        }
        $size = round($size, 2);
        switch ($rank) {
            case "1":
                $unit = "KB";
                break;
            case "2":
                $unit = "MB";
                break;
            case "3":
                $unit = "GB";
                break;
            case "4":
                $unit = "TB";
                break;
            default:
                break;
        }
        return $size . " " . $unit;
    }
}